class DailyWordModel {
  int? id;
  int? version;
  String? title;
  // 每日一句内容
  String? content;
  // 图片id
  String? pictureUrl;
  // 图片地址
  String? imageUrl;
  // 来源/作者
  String? source;
  // 标签
  String? tag;
  // 是否已收藏
  bool? isFav;
  // 收藏数
  int? favCount;
  // 点赞数
  int? repostCount;
  // 发布日期
  DateTime? publishTime;

  DailyWordModel({
    this.id,
    this.version,
    this.title,
    this.content,
    this.pictureUrl,
    this.imageUrl,
    this.source,
    this.tag,
    this.isFav,
    this.favCount,
    this.repostCount,
    this.publishTime,
  });

  DailyWordModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    version = json['version'];
    title = json['title'];
    content = json['content'];
    pictureUrl = json['pictureUrl'];
    imageUrl = json['imageUrl'];
    source = json['source'];
    tag = json['tag'];
    isFav = json['isFav'] == 1;
    favCount = json['favCount'];
    repostCount = json['repostCount'];
    var date = DateTime.tryParse(json['publishTime'] ?? "");
    if (date != null) {
      publishTime = date.toLocal();
    } else {
      publishTime = DateTime.now();
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['version'] = this.version;
    data['title'] = this.title;
    data['content'] = this.content;
    data['pictureUrl'] = this.pictureUrl;
    data['imageUrl'] = this.imageUrl;
    data['source'] = this.source;
    data['tag'] = this.tag;
    data['isFav'] = this.isFav! ? 1 : 0;
    data['favCount'] = this.favCount;
    data['repostCount'] = this.repostCount;
    data['publishTime'] = this.publishTime!.toIso8601String();
    return data;
  }
}
